<template>
  <article class="page">
    <headerbar>商家信息</headerbar>
    <section class="frame-content-sub no-bg">
      <section class="inner-content pdv-9 pdh-4">
        <div class="input-row-wrap">
          <div class="name">项目名称：</div>
          <input :readonly="status ? false : 'readonly'" v-model="form.projectName" type="text" placeholder="请填写项目名称">
        </div>
        <div class="input-row-wrap">
          <div class="name">联系人：</div>
          <input :readonly="status ? false : 'readonly'" v-model="form.consultUser" type="text" placeholder="请填写联系人姓名">
        </div>
        <div class="input-row-wrap">
          <div class="name">联系电话：</div>
          <input :readonly="status ? false : 'readonly'" v-model="form.consultTelephone" type="text" placeholder="请填写联系电话">
        </div>
        <div class="input-row-wrap">
          <div class="name">项目简介：</div>
          <textarea :readonly="status ? false : 'readonly'" v-model="form.projectContext" placeholder="请简要本项目的内容" name="" cols="30" rows="6"></textarea>
        </div>
        <div class="input-row-wrap">
          <div class="name">积分兑换规则：</div>
          <textarea :readonly="status ? false : 'readonly'" v-model="form.pointContext" placeholder="请说明积分兑换规则" name="" cols="30" rows="6"></textarea>
        </div>
        <div class="input-row-wrap">
          <div class="name">备注：</div>
          <textarea :readonly="status ? false : 'readonly'" v-model="form.consultRemakes" placeholder="" name="" cols="30" rows="6"></textarea>
        </div>
        <div class="pdv-6"></div>
        <div v-if="status===true" @click="save($event)" v-preventReClick="1000" class="default-block-btn">提交</div>
        <div class="pdv-5"></div>
      </section>

    </section>
  </article>
</template>

<script>
export default {
  name: 'settlementAdd',
  data() {
    return {
      spaceId: '',
      form: {
        "consultRemakes": "",//备注
        "consultTelephone": "",//联系人电话
        "consultUser": "",//联系人
        "pointContext": "",//积分规则
        "projectContext": "",//项目简介
        "projectName": ""//项目名称
      },
      status: true
    }
  },
  created(){
    console.log('this.$route.params.status',this.$route.params.status === false);
    if(this.$route.params.status === false){
      this.form = this.$route.params.form
      this.status = this.$route.params.status
    }
    console.log('this.status',this.status);
  },
  methods: {
    save(e) {
      if (e.target.disabled) {
        return false
      }
      if (this.form.projectName === '') {
        return this.tools.tip('请填写项目名称')
      }
      if (this.form.consultUser === '') {
        return this.tools.tip('请填写联系人姓名')
      }
      if (this.form.consultTelephone === '') {
        return this.tools.tip('请填写联系电话')
      }
      if(!(/^1[3456789]\d{9}$/.test(this.form.consultTelephone))){
        return this.tools.tip("手机号码有误，请重填");
      }
      if (this.form.projectContext === '') {
        return this.tools.tip('请填写项目简介')
      }
      if (this.form.pointContext === '') {
        return this.tools.tip('请填写积分规则')
      }
      this.$createDialog({
        type: 'confirm',
        title: "温馨提示",
        content: '确认提交？',
        confirmBtn: {
          text: '确定',
          active: true,
          disabled: false,
          href: 'javascript:;'
        },
        cancelBtn: {
          text: '取消',
          active: false,
          disabled: false,
          href: 'javascript:;'
        },
        onConfirm: () => {
          this.tools.showLoading('提交中...')
          console.log(this.form);
          this.fetchService.postAddConsultInfo(this.form).then(res => {
            this.tools.hideLoading()
            if (res.code !== 0) {
              return this.tools.tip(res.message)
            }
            this.tools.alert('您提交的申请已收到，谢谢！')
            this.tools.back()
          })
        },
        onCancel: () => {
        }
      }).show()
     /* this.tools.alert('您提交的申请已收到，谢谢！')
      this.tools.back()*/
    },
  }
}
</script>

<style scoped>
.input-row-wrap input, .input-row-wrap textarea {
  color: #000000;
}
</style>
